﻿namespace MeTool
{
    public static  class NumericHelper
    {
        /// <summary>
        /// 整数类型的NullIf
        /// </summary>
        /// <param name="sorc"></param>
        /// <param name="nullValue"></param>
        /// <returns></returns>
        public static int? NullIf(this int sorc, int nullValue)
        {
            return sorc == nullValue ? new int?() : sorc;
        }

        /// <summary>
        /// 长整数类型的NullIf
        /// </summary>
        /// <param name="sorc"></param>
        /// <param name="theNullValue"></param>
        /// <returns></returns>
        public static long? NullIf(this long sorc, long nullValue)
        {
            return sorc == nullValue ? new long?() : sorc;
        }

        /// <summary>
        /// 小数类型的NullIf
        /// </summary>
        /// <param name="theSorc"></param>
        /// <param name="nullValue"></param>
        /// <returns></returns>
        public static double? NullIf(this double sorc, double nullValue)
        {
            return sorc == nullValue ? new double?() : sorc;
        }

        /// <summary>
        /// 高精度小数类型的NullIf
        /// </summary>
        /// <param name="theSorc"></param>
        /// <param name="nullValue"></param>
        /// <returns></returns>
        public static decimal? NullIf(this decimal sorc, decimal nullValue)
        {
            return sorc == nullValue ? new decimal?() : sorc;
        }
    }
}
